require 'smtpcom_api'

client = SmtpcomApi::Client.new('your_api_key', 'api_url')

# Getting account
account = client.account

# Getting account attributes as hash
account.attributes # or account.to_hash

#updating account attributes:
account.company_name = 'My Company'
account.save

# Getting senders
senders = client.senders # OR senders = account.senders

# Find one sender by label or id
sender = client.sender('sender_label') # OR sender = account.sender('sender_label')

# Get sender attributes as hash
sener.attributes # OR sender.to_hash

#update sender 
sender.login    = 'new_login'
sender.password = 'new_password1'
sender.save

#creating sender
attributes = { 
  :label      => 'my_label', 
  :login      => 'my_login', 
  :password   => 'my_password1',
  :max_quota  => 10000
}
new_sender = client.add_sender attributes

# Auth by IP
# You could allow sender to login from some IP address instead of using login/pass each time
# To do that you shold first set :is_ip_based attribute to true
new_sender.is_ip_based = true
new_sender.save
# Then, add allowed IP addresse 
new_sender.add_allowed_ip('222.178.23.97')
# or remove some
new_sender.remove_allowed_ip('222.178.23.97')


# Examples how to get sender statistics data (summary/detailed delivery/campaigns/complaints/queue)
now       = Time.now.to_i
month_ago = now - 30*24*60*60

sender.summary :time_start => month_ago, :time_end => now
sender.delivery :time_start => month_ago, :time_end => now, :limit => 10, :offset => 0
sender.campaigns :time_start => month_ago, :time_end => now
sender.complaints :time_start => month_ago, :time_end => now, :limit => 10, :offset => 0
sender.queue :time_start => month_ago, :time_end => now, :limit => 10, :offset => 0




